package com.financing.util;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 格式验证工具类
 * 
 */
public class CheckUtils {
	
	/**
	 * 邮箱格式校验
	 * @param email
	 * @return
	 */
	public static boolean checkEmail(String email) {
		boolean tag = true;
		final String pattern1 = "^([a-z0-9A-Z_]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
		final Pattern pattern = Pattern.compile(pattern1);
		final Matcher mat = pattern.matcher(email.trim());
		if (!mat.find()) {
			tag = false;
		}
		return tag;
	}

	/**
	 * 密码格式校验
	 * @param email
	 * @return
	 */
	public static boolean checkPassword(String pass) {
		return Pattern.matches("^[a-zA-Z\\d]{6,20}$", pass);
	}

	/**
	 * 手机格式校验
	 * @param cardNo
	 * @return
	 */
	public static boolean checkMoible(String phone) {
		String regExp = "^((13[0-9])|(15[^4])|(18[0-9])|(17[0-8])|(147))\\d{8}$";
		Pattern p = Pattern.compile(regExp);
		Matcher m = p.matcher(phone);
		return m.find();//boolean
	}

	/**
	 * 身份证格式校验
	 * @param cardNo
	 * @return
	 */
	public static boolean checkCertNum(String cardNo) {
		CheckIdCard checkIdCard = new CheckIdCard(cardNo);
		return checkIdCard.validate();
	}
}
